/**
 * Project:   dtu.fmes.googleloon
 * File:      TimeOfDay.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright:	Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * 				Nicolai Sonne [ NicolaiSonne@hotmail.com.com ]
 * Date:      Dec 11, 2013
 */

package dtu.fmes.loon.model;

import java.util.List;

/**
 * 
 * @author Bartosz Cichecki, Nicolai Sonne
 */
public class Balloon {

	private Integer id = null;

	private Double latitude = null;

	private Double longitude = null;

	private Double altitude = null;

	private Double targetAltitude = null;

	private Vector targetPosition = null;

	private List<Vector> optimalPos = null;

	private Long lastUpdated = null;

	private Double currentBatteryCapacity = null;

	private boolean isAlive = true;

	private boolean canBeRevived = true;

	public Balloon() {

	}

	public Balloon(Integer id, Double latitude, Double longitude, Double altitude, Double currentBatteryCapacity) {
		this(id, latitude, longitude, altitude, null, null, null, null, currentBatteryCapacity, true, true);
	}

	public Balloon(Integer id, Double latitude, Double longitude, Double altitude, Double targetAltitude, Vector targetPosition,
	        List<Vector> optimalPos, Long lastUpdated, Double currentBatteryCapacity, boolean isAlive, boolean canBeRevived) {
		super();
		this.id = id;
		this.latitude = latitude;
		this.longitude = longitude;
		this.altitude = altitude;
		this.targetAltitude = targetAltitude;
		this.targetPosition = targetPosition;
		this.optimalPos = optimalPos;
		this.lastUpdated = lastUpdated;
		this.currentBatteryCapacity = currentBatteryCapacity;
		this.isAlive = isAlive;
		this.canBeRevived = canBeRevived;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Balloon other = (Balloon) obj;
		if (altitude == null) {
			if (other.altitude != null) {
				return false;
			}
		} else if (!altitude.equals(other.altitude)) {
			return false;
		}
		if (canBeRevived != other.canBeRevived) {
			return false;
		}
		if (currentBatteryCapacity == null) {
			if (other.currentBatteryCapacity != null) {
				return false;
			}
		} else if (!currentBatteryCapacity.equals(other.currentBatteryCapacity)) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (isAlive != other.isAlive) {
			return false;
		}
		if (lastUpdated == null) {
			if (other.lastUpdated != null) {
				return false;
			}
		} else if (!lastUpdated.equals(other.lastUpdated)) {
			return false;
		}
		if (latitude == null) {
			if (other.latitude != null) {
				return false;
			}
		} else if (!latitude.equals(other.latitude)) {
			return false;
		}
		if (longitude == null) {
			if (other.longitude != null) {
				return false;
			}
		} else if (!longitude.equals(other.longitude)) {
			return false;
		}
		if (optimalPos == null) {
			if (other.optimalPos != null) {
				return false;
			}
		} else if (!optimalPos.equals(other.optimalPos)) {
			return false;
		}
		if (targetAltitude == null) {
			if (other.targetAltitude != null) {
				return false;
			}
		} else if (!targetAltitude.equals(other.targetAltitude)) {
			return false;
		}
		if (targetPosition == null) {
			if (other.targetPosition != null) {
				return false;
			}
		} else if (!targetPosition.equals(other.targetPosition)) {
			return false;
		}
		return true;
	}

	public Double getAltitude() {
		return altitude;
	}

	public Double getCurrentBatteryCapacity() {
		return currentBatteryCapacity;
	}

	public Balloon getExportClone(Simulation simulation) {
		Balloon exportBalloon = new Balloon(getId(), getLatitude(), getLongitude(), getAltitude(), getTargetAltitude(), null, null,
		        getLastUpdated(), getCurrentBatteryCapacity(), isAlive(), isCanBeRevived());

		if (simulation.isShowTargetPosition()) {
			exportBalloon.setTargetPosition(getTargetPosition());
		}

		if (simulation.isShowOptimailPositions()) {
			exportBalloon.setOptimalPos(getOptimalPos());
		}

		return exportBalloon;
	}

	public Integer getId() {
		return id;
	}

	public Long getLastUpdated() {
		return lastUpdated;
	}

	public Double getLatitude() {
		return latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public List<Vector> getOptimalPos() {
		return optimalPos;
	}

	public Double getTargetAltitude() {
		return targetAltitude;
	}

	public Vector getTargetPosition() {
		return targetPosition;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (altitude == null ? 0 : altitude.hashCode());
		result = prime * result + (canBeRevived ? 1231 : 1237);
		result = prime * result + (currentBatteryCapacity == null ? 0 : currentBatteryCapacity.hashCode());
		result = prime * result + (id == null ? 0 : id.hashCode());
		result = prime * result + (isAlive ? 1231 : 1237);
		result = prime * result + (lastUpdated == null ? 0 : lastUpdated.hashCode());
		result = prime * result + (latitude == null ? 0 : latitude.hashCode());
		result = prime * result + (longitude == null ? 0 : longitude.hashCode());
		result = prime * result + (optimalPos == null ? 0 : optimalPos.hashCode());
		result = prime * result + (targetAltitude == null ? 0 : targetAltitude.hashCode());
		result = prime * result + (targetPosition == null ? 0 : targetPosition.hashCode());
		return result;
	}

	public boolean isAlive() {
		return isAlive;
	}

	public boolean isCanBeRevived() {
		return canBeRevived;
	}

	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	public void setAltitude(Double altitude) {
		this.altitude = altitude;
	}

	public void setCanBeRevived(boolean canBeRevived) {
		this.canBeRevived = canBeRevived;
	}

	public void setCurrentBatteryCapacity(Double currentBatteryCapacity) {
		this.currentBatteryCapacity = currentBatteryCapacity;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setLastUpdated(Long lastUpdated) {
		this.lastUpdated = lastUpdated;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public void setOptimalPos(List<Vector> optimalPos) {
		this.optimalPos = optimalPos;
	}

	public void setTargetAltitude(Double targetAltitude) {
		this.targetAltitude = targetAltitude;
	}

	public void setTargetPosition(Vector targetPosition) {
		this.targetPosition = targetPosition;
	}

	@Override
	public String toString() {
		return "Balloon [id=" + id + ", latitude=" + latitude + ", longitude=" + longitude + ", altitude=" + altitude + ", targetAltitude="
		        + targetAltitude + ", targetPosition=" + targetPosition + ", optimalPos=" + optimalPos + ", lastUpdated=" + lastUpdated
		        + ", currentBatteryCapacity=" + currentBatteryCapacity + ", isAlive=" + isAlive + ", canBeRevived=" + canBeRevived + "]";
	}

}
